<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>文字颜色切换器</title>
    <style>
        body {
            font-family: 'Microsoft Yahei', sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: 50px;
        }
        .container {
            background-color: #f8f9fa;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            width: 300px;
        }
        select {
            width: 200px;
            padding: 8px;
            margin: 10px 0;
            border: 2px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
        }
        button {
            background-color: #007bff;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #0056b3;
        }
        #colorText {
            margin-top: 20px;
            font-size: 24px;
            font-weight: bold;
            text-align: center;
            padding: 15px;
            border: 2px dashed #ccc;
            border-radius: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2 style="text-align: center;">颜色切换演示</h2>
        <select id="colorSelect">
            <option value="">请选择颜色</option>
            <option value="red">红色</option>
            <option value="yellow">黄色</option>
            <option value="blue">蓝色</option>
            <option value="green">绿色</option>
        </select>
        
        <button onclick="changeColor()">确定</button>
        <div id="colorText">观察我的颜色变化</div>
    </div>

    <script>
        function changeColor() {
            // 获取页面元素
            const colorSelect = document.getElementById('colorSelect');
            const colorText = document.getElementById('colorText');
            
            // 获取选中的颜色值
            const selectedColor = colorSelect.value;

            // 验证是否选择了颜色
            if (!selectedColor) {
                alert("请先选择一个颜色！");
                return;
            }

            // 应用颜色变化
            colorText.style.color = selectedColor;
            
            // 添加简单的动画效果
            colorText.style.transition = "color 0.5s ease";
        }
    </script>
</body>
</html>